
#include "gainctrl.h"


void gainCtrlInit(gainCtrlH* h) {
	h->hg = 0;
	h->mflag = 1;
	h->damp = GAINDAMPCOEF;
}

void gainCtrlSet(gainCtrlH* h, float damp) {//set the damping rate
	h->damp = damp;
}

void gainCtrlMute(gainCtrlH* h, float mflag) {
	h->mflag = mflag;
}

void gainCtrlApply(gainCtrlH* h, int* x, int* y,
	float g, //linear gain value
	int len) {
	
	int i;
	float dg;

	dg = (g * h->mflag) - h->hg;
	dg = dg * h->damp;
	for (i = 0; i < len; i++) {

		h->hg += dg;

		y[i] = x[i] * h->hg;

	}

}














